<div class="right_side_operate_area">
	<?php 
		App::import('Helper', 'Accp');
	    $accp = new AccpHelper();
		$user = $session->read("User");
	?>
	<div class="right_side_title left" id="count"></div>
	<?php 
		echo '<div class="left item_add_btn">';
		echo '<a style="margin-left:15px;" id="sendalert" onclick="showmsgview()">发送私信</a>';
		echo '</div>';
	?>
<!--	<input type="button" id="clear" onclick="clearMyChoose('choice','chooseAll')" value="清空所选"/>-->
	<div class="left item_add_btn"  style="display:none;" id="clearChoose">
	<a style="margin-left:15px;" id="clear" onclick="clearMyChoose('choice','chooseAll')" >清空所选</a>
	</div>
	
	<form onsubmit="return searchperson()">
		<div class="right search_box">
			
		    	<div class="left search_text">
		    		<?php echo $form->text('Project.search_person',array('placeholder'=>'搜索人员名称','value'=>$person, 'id'=>'search_person', 'class'=>'text_box'));?>
		    	</div>
		        <div class="left search_btn"><input type="submit" value=""/></div>
	        <div class="clear"></div>
	    </div>
		
		<div class="right search_box">
		    	<div class="left search_text">
		    		<?php echo $form->text('Project.keyword',array('placeholder'=>'搜索企业名称','value'=>$keyword, 'id'=>'search', 'class'=>'text_box'));?>
		    	</div>
		        <div class="left search_btn"><input type="submit" value=""/></div>
	      
	        <div class="clear"></div>
	    </div>
    </form>
    
    <div class="term_choose_area right">
    	<a class="term_choose_btn" id="term_choose_btn" title="选择"></a>
    	<div class="screen_list" id="screen_list" style="display:none;visibility:hidden;">
    		<ul style="width:500px;list-style:none">
    			<div align="center" style="font-size:15px;"><font color=red>所属产业</font></div>
    			<?php
    				if(!empty($_GET["indus"])) 
    				{
    					$indus = rtrim(urldecode($_GET['indus']),",");
    					$indus = explode(",", $indus);
    				}
	    			foreach($industrys as $key=>$strindustry)
	    			{
	    				$checked = "";
	    				if(!empty($indus))
	    				{
		    				foreach($indus as $indu)
		    				{
		    					if($key == $indu)
		    					{
		    						$checked = "checked";
		    					}
		    				}
	    				}
	    				echo '<li style="width:110px;float:left;margin-right:15px;line-height:20px">';
	   					echo "<input type='checkbox' name='industry' $checked value='$key'/>".$strindustry;
						echo '</li>';
	    			}
    			?>
    			<div class="clear"></div>
    			<hr/>
    			
    			<div align=center style="font-size:15px;"><font color=red>负责方向</font></div>
    			<?php 
    				
    				$faren_checked = "";
    				if(!empty($_GET["faren"]))
    					$faren_checked = "checked";
    				
    				echo "<li style='width:100px;float:left;margin-right:15px;line-height:20px'>";
    				echo "<input type='checkbox' name='faren' $faren_checked value='0'/>法人";
    				echo "</li>";
    				
    				if(!empty($_GET["contype"])) 
    				{
    					$conts = rtrim(urldecode($_GET['contype']),",");
    					$conts = explode(",", $conts);
    				}
	    			foreach($contype as $key=>$strcontype)
	    			{
	    				$checked = "";
	    				if(!empty($conts))
	    				{
	    					foreach($conts as $cont)
		    				{
		    					if($key == $cont)
		    					{
		    						$checked = "checked";
		    					}
		    				}
	    				}
	    				echo '<li style="width:100px;float:left;margin-right:15px;line-height:20px">';
	   					echo "<input type='checkbox' name='contype' $checked value='$key'/>".$strcontype;
						echo '</li>';
	    			}
    			?>
    		</ul>
    		
    		<div class="clear"></div>
    		<div align=center><input type="button" value="查询" onclick='setindustry()' /></div>
    		
    		<div id="industry" style="display:none"><?php echo $industry?></div>
    		<div id="contype" style="display:none"><?php echo $direction?></div>
    		<div id="faren" style="display:none"><?php echo $faren?></div>
    	</div>
    </div>
	
	<div class="clear"></div>
</div>				   
<div class="right_side_scollbar">
    <div class="detail_info_panel">
        <div class="items_list">
        	<table>
            	<tr>
            		<th>企业名称</th> 
                    <th style=text-align:left><label><input id='chooseAll' type='checkbox' onclick="ChkAllClick('choice', 'chooseAll')">姓名</label></th>
                    <th>联系电话</th>
                    <th>邮箱</th>
                    <th>负责方向</th>             
                </tr>
                <?php 
				foreach($objcompanies as $company)
				{	
					$company_id = $company["SearchCompany"]["id"];
					$company_name = $company["SearchCompany"]["company_name"];
					$contact_name = $company["SearchCompany"]["contact"];//获取负责人的id
					$contact_tel = $company["SearchCompany"]["tel"];//获取负责人的电话
					$contact_email = $company["SearchCompany"]["email"];//获取负责人的邮件
					
					
					$company_people = $company["SearchPerson"];
					$contact = array("person_name"=>$contact_name,"tel"=>$contact_tel,'email'=>$contact_email,'contypeid'=>'0','cid'=>'');
					$company_flag = true;
					if(!empty($cids) && !empty($company)){
						if(in_array($company_id,$company_ids) == false) $company_flag = false;
					}
					if((!empty($_GET["faren"]) || (empty($_GET["faren"])&&empty($_GET["contype"]))) && $flag && $company_flag)
						array_unshift($company_people,$contact);//把负责人信息的数组插入到公司员工数组的第一个
					$people_num = count($company_people);
					$i = 0;
					
					if(!empty($company_people))
					{
						foreach($company_people as $key=>$person)
						{
							$name = $person["person_name"];
							$tel = $person["tel"];
							$email = $person["email"];
							$userid = $accp->getuserid($objusers,$email);
							
							//根据负责方向的id获取
							$contypeid = $person["contypeid"];
							if($contypeid == "0")
								$value = "法人";
							else{
								$Codevalue = ClassRegistry::init('Codevalue')->findById($contypeid);
								$value = $Codevalue["Codevalue"]["value"];
							}
							
							echo "<tr class='per_list'>";		
							if($i == 0)											
								echo "<td rowspan='".$people_num."'>$company_name</td>";	
							echo "<td style='text-align:left'><label><input name='choice' type='checkbox' value='$userid'>$name</label></td>";
							echo "<td>$tel</td>";
							echo "<td>$email</td>";
							echo "<td>$value</td>";			
							echo "</tr>";
							$i++;
						}
						
					}
				 }
				?>
            </table>
		</div>
    </div>
</div>
<div id="message" title="发送私信">
</div>
<script>
var webpath=$("#getpath").attr('href');
var urlpath=webpath+"users/companyperson?seach=all";


function setindustry(){
    var inid=''; 
	$('input[name="industry"]:checked').each(function(){ 
		inid += $(this).val()+','; 
	}); 
	$("#industry").html(inid);

    var contype=''; 
	$('input[name="contype"]:checked').each(function(){ 
		contype += $(this).val()+','; 
	}); 
	$("#contype").html(contype);

	var faren=''; 
	$('input[name="faren"]:checked').each(function(){ 
			faren += $(this).val()+','; 
	}); 
	$("#faren").html(faren);
	
	searchperson();
}

if($("#search").val()!=""){
	$("#search").focus();
}
if($("#search_person").val()!=""){
	$("#search_person").focus();
}


function searchperson()
{	
	var search=$("#search").val();
	if(search=="搜索企业名称"){
		search="";
	}
	var search_person = $("#search_person").val();
	if(search_person=="搜索人员名称"){
		search_person="";
	}
	var inid=$("#industry").html();
	var faren = $("#faren").html();
	var contype = $("#contype").html();
	if(search=="" && inid=="" && search_person=="" && contype=="" && faren==""){
		location.href=urlpath;
	}else{	
		if(inid.trim() != "," && inid.trim() != ""){
			urlpath+="&indus="+inid.trim();
		}
		if(contype.trim() != "," && contype.trim() != ""){
			urlpath+="&contype="+encodeURIComponent(contype.trim());
		}
		if(faren.trim() != "," && faren.trim() != ""){
			urlpath+="&faren="+encodeURIComponent(faren.trim());
		}
		if(search.trim()!=""){
			urlpath+="&keyword="+encodeURIComponent(search.trim());
		}	
		if(search_person.trim()!=""){
			urlpath+="&person="+encodeURIComponent(search_person.trim());
		}		
		location.href=urlpath;
	}
	return false;
}

function focuseEV(C,B,A){
	if(window.attachEvent){
		C.attachEvent("on"+B,A);
	}else{
		if(window.addEventListener){
			C.addEventListener(B,A,false);
		}
	}
}

focuseEV(document,"click",function(E){
	var E=E||window.event;
	var A=E.target||E.srcElement;
	var D=window.event?E.button:E.which;
	var C=G("term_choose_btn"),B=G("screen_list");
	while(A&&A!=document.body&&A.tagName.toLowerCase()!="html"){
		if(A==C){break}
		if(A==B){break}
		A=A.parentNode
	}
	if(A==B){
	}else if(A!=C){
		B.style.display="none"
			B.style.visibility="hidden"
	}else{
		if(D<2){
			B.style.display=B.style.display=="block"?"none":"block";
			B.style.visibility=B.style.visibility=="hidden"?"visible":"hidden";
		}
	}
});

//全选功能
function ChkAllClick(sonName, cbAllId)
{
     var arrSon = document.getElementsByName(sonName);
	 var cbAll = document.getElementById(cbAllId);
	 var tempState=cbAll.checked;
	 for(i=0;i<arrSon.length;i++) 
	 {
	  	if(arrSon[i].checked!=tempState)
	           arrSon[i].click();
	 }
} 

//页面刷新时前一个页面所勾选的选项的选择
function clearAllChecked()
{
	 $("#chooseAll").attr("checked",false);	
	 $("input[name='choice']").each(function () {
        $(this).attr("checked", false);
     });
}

//清空所选
function clearMyChoose(sonName,cbAllId)
{
	var cbAll = document.getElementById(cbAllId);	
	if(cbAll.checked == true)
			cbAll.click();
	var arrSon = document.getElementsByName(sonName);
	for(i =0; i < arrSon.length;i++)
	{
		
		if(arrSon[i].checked == true)
			arrSon[i].click();
	}
}

$("input[name='choice']").click(countChecked);

function countChecked() {
  var n = $("input[name='choice']:checked").length;
  $("#count").eq(0).html("<strong>有<font color='red'>"+n+"</font> 个被选中!</strong>");
  
  //如果有选中人，那么显示"清除所选"的按钮;若没有选中，那么"清除所选"的按钮不显示
  if(n != 0)
	  $("#clearChoose").css("display","block");
  else
	  $("#clearChoose").css("display","none");

  //把所选择的人的id放到一个文本域中
  var s=''; 
  $('input[name="choice"]:checked').each(function(){ 
    s+=$(this).val()+','; 
  }); 
  $("#useridlist").val(s);
  $("#sender").val(<?php echo $user["id"];?>);
}
function showmsgview(){

	 var n = $("input[name='choice']:checked").length;

	 if(n==0)
	 {
		 showmessage("请选择联系人");
	 }else
	 {
		 $("#message").dialog( "open" );
	 }
}
$(function() {
	$("#message").dialog({
		autoOpen: false,
		height: 300,
		width: 800,
		modal:true,
		resizable: false
	});
	$("#cancel").click(function() {
		$("#message").dialog( "close" );
	});
});
function getmsgpage(){	
	var urlpath="<?php echo $accp->path;?>/priMsg";	
	$.ajax({     	   
        url: urlpath, 
        success:function(data){
        	$("#message").html(data);
        	$(":file").uniform();
        }
       })
  $("#sender").val(<?php echo $user["id"];?>);
}

clearAllChecked();
getmsgpage();
countChecked();

funPlaceholder(document.getElementById("search_person"));
funPlaceholder(document.getElementById("search"));

</script>